package com.zh.jetpackmvvm.ext.lifecyle

import android.os.Handler
import androidx.lifecycle.*

/**
 * @author :zhouh
 * email：zhouhe@sixarm.cn
 * time：2020-06-01
 * company：山东六臂网络科技有限公司
 * desc：
 */
class KtxHandler(var lifecycleOwner: LifecycleOwner, callback: Callback) : Handler(callback),
    LifecycleObserver {

    init {
        lifecycleOwner.lifecycle.addObserver(this)
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    private fun onDestroy() {
        removeCallbacksAndMessages(null)
        lifecycleOwner.lifecycle.removeObserver(this)
    }
}